const express = require("express");
const router = express.Router();
const staff = require("../db/services/staff");
const lodash = require("lodash");

router.post("/addStaff", async (req, res) => {
    const info = await staff.addItem(req.body);  
    res.send(info);
})

router.delete('/delStaff', async (req, res) => {
    const info = await staff.delItem(req.query);
    res.send(info);
})

router.put("/editStaff/:id", async (req, res) => {
    console.log('updateeeeeeeeeeeeee111:',req.query, req.params, req.body)
    const info = await staff.updateItem(req.params, req.body);  
    res.send(info);
})

router.get("/staffList", async (req, res) => {
    const { current: page, pageSize } = req.query;
    const where =lodash.omit(req.query, ['current', 'pageSize']);

    const info = await staff.getList({
        // attributes: ['id', 'name', 'birthday', 'created_at'],
        where,
        // sort: [['age', 'asc']],
        paging: true,
        page: parseInt(page),
        pageSize: parseInt(pageSize),
    });
    res.send(info);
})
module.exports = router;